#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys
import os
from rpy import *
from PyQt4 import QtGui
from PyQt4 import QtCore

class MainWindow(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.resize(640, 480)
        self.center()
        self.setWindowTitle('R-GUI')
        self.setToolTip('R-GUI')

        self.square = QtGui.QFrame(self)
        self.square.setGeometry(20, 20, 350, 350)
        self.square.setStyleSheet("QWidget { background-color: White }")
        self.square.setToolTip('Graphic display')

    def center(self):
        screen = QtGui.QDesktopWidget().screenGeometry()
        size   = self.geometry()
        self.move((screen.width()-size.width())/2,
                (screen.height()-size.height())/2)

    def closeEvent(self, event):
        reply = QtGui.QMessageBox.question(self, 'Message',
                "Are you sure to quit?", QtGui.QMessageBox.Yes | 
                QtGui.QMessageBox.No, QtGui.QMessageBox.No)

        if reply == QtGui.QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()


app = QtGui.QApplication(sys.argv)

wid = MainWindow()
wid.show()

u = range(10)  # set up another scatter plot, this one local
e = 5*[0.25,-0.25]
v = u[:]
for i in range(10): v[i] += e[i]
r.plot(u,v)
r.assign('remoteu',u)  # ship local u to R
r.assign('remotev',v)  # ship local v to R
r('plot(remoteu,remotev)')  # plot there

sys.exit(app.exec_())

